package me.jessyan.armscomponent.app.mvp.ui.adapter;

import android.app.Activity;
import android.content.Context;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;

import com.google.android.material.internal.ContextUtils;
import com.google.gson.Gson;
import com.jess.arms.base.BaseHolder;
import com.jess.arms.base.DefaultAdapter;

import java.util.List;

import javax.inject.Inject;

import me.jessyan.armscomponent.app.R;
import me.jessyan.armscomponent.app.mvp.model.entity.Question;
import me.jessyan.armscomponent.app.mvp.ui.holder.ChoiceQuestionItemHolder;
import me.jessyan.armscomponent.app.mvp.ui.holder.JudgeQuestionItemHolder;
import me.jessyan.armscomponent.app.mvp.ui.holder.QAQuestionItemHolder;
import me.jessyan.armscomponent.commonres.widget.toast.ToastView;

/**
 * Desc:
 * Created by taoze
 * on 2021/10/20
 **/
public class UserTestLevelAdapter extends DefaultAdapter<Question> {

    public static int TYPE_CHOICE = 1;
    public static int TYPE_JUDGE = 2;
    public static int TYPE_QA = 3;

    Context mContext;

    public UserTestLevelAdapter(Context context, List<Question> infos)
    {
        super(infos);
        this.mContext = context;
    }

    public List<Question> getAnswers(){
        return getInfos();
    }


    public boolean checkAnswers() {
        List<Question> datas = getInfos();
        for (int i = 0; i < datas.size(); i++) {
            Log.d("taoze",i+1+":" +datas.get(i).getContentAra()+" /// "+datas.get(i).getAnswer());
            if (TextUtils.isEmpty(datas.get(i).getAnswer())) {
                ToastView.getInstance().showToast(mContext, "请先完成答题");
                return false;
            }
        }
        return true;
    }

    @Override
    public int getItemViewType(int position) {
        Question question = getInfos().get(position);
        if(question.getQuestionType() == 1){
            return TYPE_CHOICE;
        }else if(question.getQuestionType() == 2){
            return TYPE_JUDGE;
        }else{
            return TYPE_QA;
        }
    }

    @Override
    public BaseHolder<Question> getHolder(View v, int viewType) {
        if(viewType == TYPE_JUDGE){
            return new JudgeQuestionItemHolder(v);
        }else if(viewType == TYPE_CHOICE){
            return new ChoiceQuestionItemHolder(v);
        }else{
            return new QAQuestionItemHolder(v);
        }
    }

    @Override
    public int getLayoutId(int viewType) {
        if(viewType == TYPE_JUDGE){
            return R.layout.adapter_user_question_judge;
        }else if(viewType == TYPE_CHOICE){
            return R.layout.adapter_user_question_choice;
        }else{
            return R.layout.adapter_user_question_qa;
        }
    }
}
